/** 现在版本暂时放弃使用，请勿修改 */ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
import React from "react";
// import Container from "@/compoents/container";
// import FullScreenNav from "@/compoents/full-screen-nav";
import styles from "./signUp.module.less";
import classnames from "classnames";
import { useTranslation } from "react-i18next";
import useCallBackState from "../../hooks/useCallBackState";
import useSuperLock from "../../hooks/useSuperLock";
import toast from "../../compoents/toast";
import images from "../../assets";
import LinearInput from "../../compoents/linear-input";
import PhoneInput from "../../compoents/phone-input";
import VerificationCode from "../../compoents/verifiaction-code";
import Loading from "../../compoents/s-loading";
import utilsBase from "../../utils/basc";
import { register, checkEmail, checkPhone } from "../../api/user";
import { findAccount } from "../../api/wallet";
import { KEYCONST } from "../../enums";
import { useDispatch } from "react-redux";
import useServices from "../../hooks/useRequest";
import AccountLayout from "../../compoents/account-layout";
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
function SignUp() {
    var handleSwitch = function handleSwitch() {
        setState({
            isEmail: !state.isEmail,
            email: "",
            phone: ""
        });
    };
    var handleSignIn = function handleSignIn() {
        dispatch.app.PUSH("/login");
    };
    var _useCallBackState = _sliced_to_array(useCallBackState({
        isEmail: true,
        email: "",
        area: "+86",
        phone: "",
        password: "",
        code: "",
        checked: false,
        account: "",
        passwordError: false,
        accountError: false
    }), 2), state = _useCallBackState[0], setState = _useCallBackState[1];
    var t = useTranslation().t;
    var dispatch = useDispatch();
    var services = useServices({
        findAccount: findAccount,
        checkEmail: checkEmail,
        checkPhone: checkPhone
    });
    var checkRegistration = function() {
        if (state.isEmail && !state.email) return;
        if (!state.isEmail && !state.phone) return;
        if (state.isEmail && !utilsBase.checkEmail(state.email)) {
            toast.createToast({
                type: "errToast",
                message: "Enter a valid Email!"
            });
            setState({
                accountError: true
            });
            return;
        }
        var checkFetch = state.isEmail ? services.checkEmail : services.checkPhone;
        var data = state.isEmail ? {
            email: state.email.toString().replace(/\s/g, "")
        } : {
            phone: state.phone.toString().replace(/\s/g, "")
        };
        if (state.isEmail && !data.email) return;
        if (!state.isEmail && !data.phone) return;
        checkFetch(data, false).then(function(res) {
            if (res.code == 200) {
                setState({
                    account: state.isEmail ? state.email : state.phone,
                    accountError: false
                });
            } else {
                toast.createToast({
                    type: "errToast",
                    message: state.isEmail ? "Email has been registered!" : "Phone number has been registered!"
                });
                setState({
                    account: "",
                    accountError: true
                });
            }
        }).catch(function() {});
    };
    var checkPassword = function() {
        if (!state.password) return;
        if (state.password.length < 8 || state.password.length > 16) {
            toast.createToast({
                type: "errToast",
                message: "The password must be at least 8 characters!"
            });
            setState({
                passwordError: true
            });
            return;
        }
        if (!/^[a-zA-Z0-9]{8,16}$/.test(state.password)) {
            toast.createToast({
                type: "errToast",
                message: "The password must be numbers or letters!"
            });
            setState({
                passwordError: true
            });
            return;
        }
        setState({
            passwordError: false
        });
    };
    var _useSuperLock = _sliced_to_array(useSuperLock(/*#__PURE__*/ _async_to_generator(function() {
        var data;
        return _ts_generator(this, function(_state) {
            switch(_state.label){
                case 0:
                    if (state.password.trim().length < 8 || state.isEmail && !utilsBase.checkEmail(state.email) || !state.isEmail && !state.phone || utilsBase._checkCode(state.code)) {
                        toast.createToast({
                            message: t("signIn0")
                        });
                        return [
                            2
                        ];
                    }
                    data = {
                        verificationCode: state.code,
                        password: state.password,
                        email: undefined,
                        areaCode: undefined,
                        phone: undefined,
                        loginName: undefined
                    };
                    if (state.isEmail) {
                        data.loginName = state.email;
                    } else {
                        data.loginName = "".concat(state.area, "-").concat(state.phone);
                    }
                    return [
                        4,
                        register(data, false).then(function() {
                            var _ref = _async_to_generator(function(res) {
                                return _ts_generator(this, function(_state) {
                                    if (res.code === 200) {
                                        localStorage.setItem(KEYCONST.token, JSON.stringify(res.data));
                                        localStorage.setItem(KEYCONST.userInfo, JSON.stringify(res.data.userDetail));
                                        dispatch.app.SET_USER_INFO(res.data.userDetail);
                                        services.findAccount({}, false).then(function(resa) {
                                            localStorage.setItem(KEYCONST.wallet, JSON.stringify(resa.data));
                                            dispatch.app.PUSH({
                                                path: "/home"
                                            });
                                        });
                                    } else {
                                        toast.createToast({
                                            message: res.msg,
                                            type: "errToast"
                                        });
                                    }
                                    return [
                                        2
                                    ];
                                });
                            });
                            return function(res) {
                                return _ref.apply(this, arguments);
                            };
                        }())
                    ];
                case 1:
                    _state.sent();
                    return [
                        2
                    ];
            }
        });
    })), 2), handleSignUp = _useSuperLock[0], loading = _useSuperLock[1];
    var canSelect = state.checked && (state.isEmail ? state.email.trim().length > 0 : state.phone.trim().length > 0) && state.password.trim().length > 0 && state.code.trim().length > 0 && state.account && !state.passwordError && !state.accountError;
    return /*#__PURE__*/ _jsx(AccountLayout, {
        backFn: function() {
            dispatch.app.BACK();
        },
        children: /*#__PURE__*/ _jsx("div", {
            className: styles.page,
            children: /*#__PURE__*/ _jsxs("div", {
                className: styles.content,
                children: [
                    /*#__PURE__*/ _jsx("div", {
                        className: classnames(styles.flex, styles.signInBox),
                        children: /*#__PURE__*/ _jsx("div", {
                            className: styles.signIn,
                            children: t("loginHeader34")
                        })
                    }),
                    /*#__PURE__*/ _jsxs("div", {
                        className: styles.labelBox,
                        children: [
                            /*#__PURE__*/ _jsx("div", {
                                className: styles.label,
                                children: state.isEmail ? t("loginHeader0") : t("loginHeader1")
                            }),
                            state.isEmail ? /*#__PURE__*/ _jsx(LinearInput, {
                                onBlur: checkRegistration,
                                value: state.email,
                                onChange: function(value) {
                                    return setState({
                                        email: value
                                    });
                                },
                                placeholder: t("loginHeader31"),
                                maxlength: 30,
                                error: state.accountError
                            }) : /*#__PURE__*/ _jsx(PhoneInput, {
                                value: state.phone,
                                onChange: function(area, phone) {
                                    return setState({
                                        area: area,
                                        phone: phone
                                    });
                                },
                                maxlength: 15
                            })
                        ]
                    }),
                    /*#__PURE__*/ _jsxs("div", {
                        className: styles.labelBox,
                        children: [
                            /*#__PURE__*/ _jsx("div", {
                                className: styles.label,
                                children: t("loginHeader2")
                            }),
                            /*#__PURE__*/ _jsx(LinearInput, {
                                onBlur: checkPassword,
                                value: state.password,
                                onChange: function(value) {
                                    return setState({
                                        password: value
                                    });
                                },
                                placeholder: t("loginHeader33"),
                                maxlength: 16,
                                type: "safe-password",
                                password: true,
                                error: state.passwordError
                            })
                        ]
                    }),
                    /*#__PURE__*/ _jsx("div", {
                        className: styles.label,
                        children: t("loginHeader35")
                    }),
                    /*#__PURE__*/ _jsx(VerificationCode, {
                        target: state.isEmail ? state.email : state.area + "-" + state.phone,
                        errMessage: state.isEmail ? "email cannot be empty" : "phoneNumber cannot be empty",
                        value: state.code,
                        onChange: function(value) {
                            return setState({
                                code: value
                            });
                        }
                    }),
                    /*#__PURE__*/ _jsxs("div", {
                        className: styles.checkBox,
                        children: [
                            !state.checked && /*#__PURE__*/ _jsx("div", {
                                className: styles.agree,
                                style: {
                                    backgroundImage: "url(".concat(images.signUpBac, ")")
                                },
                                children: t("signUp1")
                            }),
                            /*#__PURE__*/ _jsx("div", {
                                className: styles.checkContent,
                                children: /*#__PURE__*/ _jsx("img", {
                                    src: state.checked ? images.checked : images.unchecked,
                                    className: styles.check,
                                    onClick: function() {
                                        return setState({
                                            checked: !state.checked
                                        });
                                    }
                                })
                            }),
                            /*#__PURE__*/ _jsxs("div", {
                                className: styles.policyText,
                                children: [
                                    " " + t("loginHeader8") + " ",
                                    /*#__PURE__*/ _jsx("span", {
                                        onClick: function() {
                                            window.open("https://www.nfkings.com/noa/TermsofUse.pdf");
                                        },
                                        className: styles.policy,
                                        children: t("loginHeader9")
                                    }),
                                    " " + t("loginHeader10") + " ",
                                    /*#__PURE__*/ _jsx("span", {
                                        className: styles.policy,
                                        onClick: function() {
                                            return window.open("https://www.nfkings.com/noa/PrivacyPolicy.pdf");
                                        },
                                        children: t("loginHeader11")
                                    })
                                ]
                            })
                        ]
                    }),
                    /*#__PURE__*/ _jsx("div", {
                        className: styles.btn,
                        style: canSelect ? {
                            background: "var(--primary)"
                        } : {},
                        onClick: function() {
                            return canSelect ? handleSignUp() : {};
                        },
                        children: loading ? /*#__PURE__*/ _jsx(Loading, {
                            color: "#fff"
                        }) : t("loginHeader26")
                    }),
                    /*#__PURE__*/ _jsxs("div", {
                        className: styles.signUpBox,
                        children: [
                            /*#__PURE__*/ _jsxs("div", {
                                className: styles.text,
                                children: [
                                    t("loginHeader13"),
                                    " "
                                ]
                            }),
                            /*#__PURE__*/ _jsx("div", {
                                className: styles.signUp,
                                onClick: function() {
                                    return handleSignIn();
                                },
                                children: t("loginHeader14")
                            })
                        ]
                    })
                ]
            })
        })
    });
}
export default SignUp;

 //# sourceMappingURL=index.js.map